stack: Don't underallocate child in interpolate-size case
authorTimm Bäder <mail@baedert.org>
Fri, 28 Oct 2016 10:56:36 +0000 (12:56 +0200)
committerTimm Bäder <mail@baedert.org>
Mon, 31 Oct 2016 18:29:36 +0000 (19:29 +0100)
In that case, we can't just rely on the stack allocation being big
enough. Especially, the child can actually be bigger than the current
stack allocation, so take that into account when positioning it.

gtk/gtkstack.c

index fd23f8a40396ecfde7a27c592f5654b4078d6ee3..cf814b7dfbf0ee7fd001829b4922b8b9f74c574c 100644 (file)
@@ -2253,22 +2253,35 @@ gtk_stack_allocate (GtkCssGadget        *gadget,
 
   if (priv->visible_child)
     {
-      int min, nat;
-      GtkAlign valign;
+      int min_width;
+      int min_height;
 
-      gtk_widget_get_preferred_height_for_width (priv->visible_child->widget,
-                                                 allocation->width,
-                                                 &min, &nat);
-      if (priv->interpolate_size)
+      gtk_widget_measure (priv->visible_child->widget, GTK_ORIENTATION_HORIZONTAL,
+                          allocation->height, &min_width, NULL, NULL, NULL);
+      child_allocation.width = MAX (child_allocation.width, min_width);
+
+      gtk_widget_measure (priv->visible_child->widget, GTK_ORIENTATION_VERTICAL,
+                          child_allocation.width, &min_height, NULL, NULL, NULL);
+      child_allocation.height = MAX (child_allocation.height, min_height);
+
+      if (child_allocation.width > allocation->width)
         {
-          valign = gtk_widget_get_valign (priv->visible_child->widget);
-          child_allocation.height = MAX (nat, allocation->height);
-          if (valign == GTK_ALIGN_END &&
-              child_allocation.height > allocation->height)
-            child_allocation.y -= nat - allocation->height;
-          else if (valign == GTK_ALIGN_CENTER &&
-                   child_allocation.height > allocation->height)
-            child_allocation.y -= (nat - allocation->height) / 2;
+          GtkAlign halign = gtk_widget_get_halign (priv->visible_child->widget);
+
+          if (halign == GTK_ALIGN_CENTER || halign == GTK_ALIGN_FILL)
+            child_allocation.x = (allocation->width - child_allocation.width) / 2;
+          else if (halign == GTK_ALIGN_END)
+            child_allocation.x = (allocation->width - child_allocation.width);
+        }
+
+      if (child_allocation.height > allocation->height)
+        {
+          GtkAlign valign = gtk_widget_get_valign (priv->visible_child->widget);
+
+          if (valign == GTK_ALIGN_CENTER || valign == GTK_ALIGN_FILL)
+            child_allocation.y = (allocation->height - child_allocation.height) / 2;
+          else if (valign == GTK_ALIGN_END)
+            child_allocation.x = (allocation->height - child_allocation.height);
         }
 
       gtk_widget_size_allocate (priv->visible_child->widget, &child_allocation);